package java67_adv3;

import java.util.*;

import review.KindMan;

public class SetTest {

	public static void main(String[] args) {
		// 无序,不重复
		Set set = new HashSet();
		set.add("dog");
		set.add(Math.PI);
		set.add("cat");
		set.add("dog");
		System.out.println(set.size());// 3 4?
		System.out.println(set);
		System.out.println(">>>>>>>>>>>>>>>");
		set.add(new KindMan("雷锋"));
		set.add(new KindMan("雷锋", 32));
		set.add(new KindMan("雷锋", 34));
		System.out.println(set);
		System.out.println(set.size());
		System.out.println(">>>>>>>>>>>>>>>>>>>遍历>>>>>>>");
		// 1:转换数组
		Object[] ar = set.toArray();
		for (Object o : ar) {
			System.out.println(o);
		}
		System.out.println("---------------------");
		// 2:支持增强循环
		for (Object o : set)// 最简单
			System.out.println(o);
		System.out.println("---------------------");
		// 3 :迭代器
		Iterator ir = set.iterator();
		System.out.println(">>>" + ir.getClass().getName());
		while (ir.hasNext()) {
			Object next = ir.next();// 下一个对象
			System.out.println(next);
		}
	}

}
